package cn.jzx.smph.rest;

import cn.jzx.smph.entity.Emp;
import cn.jzx.smph.service.EmpService;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp")
@CommonsLog
public class EmpRest {
    //add update delete list
    @Autowired
    private EmpService empService;
    @GetMapping
    public List<Emp> list(){
        return empService.list();
    }

    @PostMapping
    public Boolean saveOrUpdate(@RequestBody Emp emp){
        try {
            empService.saveOrUpdate(emp);
        }catch (Exception e){
            log.error("异常了。。。。",e);
            return false;
        }
        return true;
    }

    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable("id") String id){
        try {
            empService.delete(id);
        }catch (Exception e){
            log.error("异常了。。。。",e);
            return false;
        }
        return true;
    }

}
